#coding=utf-8
#
#商品数据入库操作
#
import pymysql

def readtxt(cur):
    with open('data','r',encoding = 'utf-8')as f:
        data = f.readlines()
    for i in data:
        sd =  i.split(':')
        print(sd)
        goodsname = str(sd[0])
        gdata = str(sd[1]).strip('\n')
        cur.execute('Insert into goods (`goodsname`,`gdata`) values {0}'.format((goodsname,gdata)))
        conn.commit()
    print('插入数据完成')



if __name__ == '__main__':
    conn = pymysql.connect(host='106.14.144.54',port=3306,user='root',password='xxxx',db='QQSG',charset='utf8')
    cur = conn.cursor()
    readtxt(cur=cur)
    pass